package com.dudu.service.impl;

import org.apache.commons.lang.StringUtils;

import com.dudu.bean.AccountBean;
import com.dudu.bean.AppExtendBean;
import com.dudu.dao.RecordInfoDao;
import com.dudu.service.IRecordInfoService;

import core.CoreDao;

public class RecordInfoServiceImpl implements IRecordInfoService {

	//持久层操作类
	private RecordInfoDao recordInfoDao = new RecordInfoDao();
	
	@Override
	public int insert(CoreDao dao, String sessionId,
			String abilityType, AppExtendBean appExtendBean, AccountBean accountBean) {
		int result = -1;
		try{
			if(StringUtils.isNotBlank(sessionId) && accountBean != null && StringUtils.isNotBlank(abilityType)){
				String recordUrlStr = accountBean.getUrl_record();
				if(StringUtils.isBlank(recordUrlStr)){ //组织账号未配置录音文件推送地址时，从app账号获取
					recordUrlStr = appExtendBean.getUrl_record();
				}
				String[] pushUrlArray = recordUrlStr.split(",");
				if(pushUrlArray.length > 0){
					for(String pushUrl : pushUrlArray){
						if(StringUtils.isNotBlank(pushUrl)){
							result = this.recordInfoDao.insert(dao, sessionId, abilityType, pushUrl);
						}
					}
				} else {
					result = this.recordInfoDao.insert(dao, sessionId, abilityType, "");
				}
			}
		} catch (Exception ex){
			ex.printStackTrace();
		}
		
		return result;
	}

}
